import { request } from "@umijs/max";

// 获取分类列表
export async function getCategories(params?: any) {
  return await request('/categories/', { params });
}

// 获取分类详情
export async function getCategoryDetail(id: number) {
  return await request(`/categories/${id}/`);
}

// 创建分类
export async function createCategory(data: any) {
  return await request('/categories/', { method: 'POST', data });
}

// 更新分类
export async function updateCategory(id: number, data: any) {
  return await request(`/categories/${id}/`, { method: 'PUT', data });
}

// 删除分类
export async function deleteCategory(id: number) {
  return await request(`/categories/${id}/`, { method: 'delete' });
}

// 获取分类树
export async function getCategoryTree() {
  return await request('/categories/tree/');
}

// 获取分类下的图书
export async function getCategoryBooks(id: number) {
  return await request(`/categories/${id}/books/`);
}

// 获取分类下的子分类
export async function getCategoryChildren(id: number) {
  return await request(`/categories/${id}/children/`);
}